package com.zlsoft.web.utils;

import android.app.Activity;

import com.huawei.hms.hmsscankit.ScanUtil;
import com.huawei.hms.ml.scan.HmsScan;
import com.huawei.hms.ml.scan.HmsScanAnalyzerOptions;
import com.zlsoft.web.utils.permissions.PermissionsUtils;

/**
 * @author - qqz
 * @date - 2021-12-20/14:44
 * @note -
 * ---------------------------------------------------------------------------------------------------------------------------------
 * @modified -
 * @date -
 * @note -
 */
public class QrUtils {

    /**
     * 扫码回调本地
     */
    public final static int HW_SCAN_FOR_RESULT_LOCAL_CODE = 886;
    /**
     * 网页-需要回传数据
     */
    public final static int HW_SCAN_FOR_RESULT_WEB_CODE = 688;
    /**
     * 网页调用了重置地址-只是重置，无需返回数据给网页
     */
    public final static int HW_SCAN_FOR_REST_WEB_RESULT_WEB_CODE = 689;

    private static QrUtils mQrUtils;

    public static QrUtils getInstance() {
        if (mQrUtils == null) {
            mQrUtils = new QrUtils();
        }
        return mQrUtils;
    }

    public void QrProduct(Activity mActivity, int requestCode) {
        QrProduct(mActivity, requestCode, HmsScan.ALL_SCAN_TYPE);
    }

    public void QrProduct(Activity mActivity, int requestCode,int type) {
        PermissionsUtils.getInstance().getPermission(mActivity, mB -> {
            ScanUtil.startScan(mActivity, requestCode, new HmsScanAnalyzerOptions.Creator().setHmsScanTypes(type).create());
        });
    }


}
